package cn.itcast.demo.mq.spring;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 虎哥
 */
@Configuration
public class MqConfig {

    /**
     * 声明一个队列
     * @return 队列
     */
    @Bean
    public Queue springQueue1() {
        return new Queue("spring.queue1", true, false, false);
    }

    @Bean
    public Queue springQueue2() {
        return QueueBuilder.durable("spring.queue2").build();
    }

    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange("spring.topic.exchange", true, false);
    }

    @Bean
    public Binding queue1Binding(){
        return BindingBuilder
                .bind(springQueue1()) // 指定队列
                .to(topicExchange()) // 指定交换机
                .with("usa.#"); // 指定RoutingKey
    }
    @Bean
    public Binding queue2Binding(){
        return BindingBuilder
                .bind(springQueue2()) // 指定队列
                .to(topicExchange()) // 指定交换机
                .with("#.news"); // 指定RoutingKey
    }
}
